package com.sui.bigdata.rtcadmin.handler;

import com.sui.bigdata.rtcadmin.exception.ResourceException;
import com.sui.bigdata.rtcadmin.exception.SparkApplicationException;
import com.sui.bigdata.rtcadmin.exception.SparkConfException;
import com.sui.bigdata.rtcadmin.model.vo.CommonResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: TingWuHuang
 * @Date: 2020/5/6 15:30
 * @description
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler
    public CommonResponse sparkApplicationExcetion(SparkApplicationException e){
        logger.error("SparkApplicationException：{}", e);
        return CommonResponse.Builder.buildError(e.getMessage());
    }

    @ExceptionHandler
    public CommonResponse sparkConfException(SparkConfException e){
        logger.error("SparkConfException: {}", e);
        return CommonResponse.Builder.buildError(e.getMessage());
    }

    @ExceptionHandler
    public CommonResponse resourceException(ResourceException e){
        logger.error("ResourceException:{}", e);
        return CommonResponse.Builder.buildSuccess(e.getMessage());
    }

}
